<?php
/*
 * dragon.hu add 2015.6.16  relicsecret
*/

defined('BASEPATH') or die('forbidden');

class Relicssecret_Controller extends Controller
{
	private $conn;
	private $nameConn;
	private $nameList;
	private $copyList;
	private $exitList;
	private $inc;
	private $professiontype;
	private $chapterList;
	
	function _init()
	{
		check_level(50, segment(0), segment(1), segment(2, 'index'));
		set_time_limit(0);
		$this->inc = $this->config['inc'];
		$this->professiontype = $this->inc['type_proffessionid'];
		
		$areanum = $_SESSION['area_selected_id'];
		if ($areanum == '')
		{
			echo "<script>alert('".translate('C_SELECT_AREA_TEXT')."');</script>";
			return;
		}
		$this->nameConn = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_GAMESERVER);
		$this->nameConn->query("SELECT id, name FROM player");
		while ($n = $this->nameConn->get_array('default'))
		{
			$this->nameList[$n['id']] = $n['name'];
		}
		$this->nameConn->free_all();
		$this->copyList = get_type_fbname();
		$this->exitList=array('0'=>'3v3退出房间', '1'=>'副本服务器挂了', '2'=>'客户端狂点进入副本', '3'=>'已经在副本了如果再请求会T出',
				'4'=>'客户端主动请求退出', '5'=>'玩家掉线', '6'=>'副本完成', '7'=>'角色没登陆副本服务器', '8'=>'GM工具操作', '9'=>'死亡之塔没邀请函或者金币非法进入(一般不会发)');
		$this->chapterList = array('0' => '狩猎之丘', '1' => '失落领域', '2' => '蓝德秘境', '3' => '穆图遗迹', 
				'4' => '荒月遗迹', '5' => '暗黑神冢', '6' => '未知');
		
		$this->conn = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_LOG);
	}	
	
	function flexigrid()
	{
		list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();
		$sql = "SELECT COUNT(*) AS num FROM relics_secret WHERE {$where}";
		$one = $this->conn->one($sql);
		$total = $one['num'];
		
		$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder}" : "";
		$sql = "SELECT {$colsinfo} FROM relics_secret WHERE {$where} {$orderby} LIMIT {$offset}, {$rp}";
		$this->conn->query($sql);
		while ($n = $this->conn->get_array('default'))
		{
			$n['role_id'] = $this->nameList[$n['role_id']]."(".$n['role_id'].")";
			$n['copy_id'] = $this->copyList[$n['copy_id']]."(".$n['copy_id'].")";
			$n['exit_type'] = $this->exitList[$n['exit_type']]."(".$n['exit_type'].")";
			$n['current_chapter'] = $this->chapterList[$n['current_chapter']]."(".$n['current_chapter'].")";
			$n['profession_type'] = $this->professiontype[$n['profession_type']]."(".$n['profession_type'].")";
			
			$rows[] = array('id' => $n['id'], 'cell' => $n);
		}
		$result = array('page' => $page, 'total' => $total, 'rows' => $rows);
		$this->conn->free_all();
		echo json_encode($result);
	}
	
	function index()
	{
		$this->view->display("logbattle/relicssecret/index");
	}
}

?>